package cn.tide.question2.question;

/**
 * 第10题单例模式
 */
public class question10 {

}
/**
 * 第一种饿汉式
 */
class Single1{
    private static Single1 instance = new Single1();

    private Single1(){}

    public static Single1 getInstance(){
        return instance;
    }
}

/**
 * 第二种懒汉式
 */
class Single2{
    private static Single2 instance;

    private Single2(){}

    public static Single2 getInstance(){
        if (instance==null){
            instance = new Single2();
        }
        return instance;
    }
}


/**
 * 第三种静态内部类
 */
class Single3{
    private static class SingleHolder{
        private static final Single3 instance = new Single3();
    }
    private Single3(){}
    public static final Single3 getInstance(){
        return SingleHolder.instance;
    }
}

